#include "paramProcess.h"
#include "myTasks.h"

// 心拍频率
uint16_t heart_beat_Hz = 1;
void param_read_heart_beat(struct param_stu *param){
    LOG_FMT(PRINT_LOG"Heart beat: %d Hz\n", heart_beat_Hz);
}
void param_write_heart_beat(struct param_stu *param, const char *new_val){
    uint16_t new_Hz;

    sscanf(new_val, "%d", &new_Hz);

    if(new_Hz > 1000 || new_Hz < 1){
        LOG_FMT(PRINT_WARNNING"New value(%d) not in range(1~1000)!\n", new_Hz);
        return ;
    }

    heart_beat_Hz = new_Hz;

    task_heart_beat.timer.tick_reload = 1000/heart_beat_Hz;
    task_heart_beat.timer.tick_counts = 1000/heart_beat_Hz;

    LOG_FMT(PRINT_LOG"Set heart beat to %d Hz\n", 1000/heart_beat_Hz);
}

// 蓝灯闪烁频率
uint16_t led_blue_Hz = 5;
void param_read_blink_Hz(struct param_stu *param){
    LOG_FMT(PRINT_LOG"Heart beat: %d Hz\n", led_blue_Hz);
}
void param_write_blink_Hz(struct param_stu *param, const char *new_val){
    uint16_t new_Hz;

    sscanf(new_val, "%d", &new_Hz);

    if(new_Hz > 100 || new_Hz < 1){
        LOG_FMT(PRINT_WARNNING"New value(%d) not in range(1~100)!\n", new_Hz);
        return ;
    }

    led_blue_Hz = new_Hz;

    task_blink.timer.tick_reload = 500/led_blue_Hz;
    task_blink.timer.tick_counts = 500/led_blue_Hz;

    LOG_FMT(PRINT_LOG"Set blink to %d Hz\n", 500/led_blue_Hz);
}


struct param_stu param_list[] = {
    { // 心拍任务频率
        .param_name = "heart_beat_Hz",
        .param_read = param_read_heart_beat,
        .param_write = param_write_heart_beat,
    },

    { // 蓝灯闪烁频率
        .param_name = "blink_Hz",
        .param_read = param_read_blink_Hz,
        .param_write = param_write_blink_Hz,
    },


    // 末尾项
    {
        .param_name = " ",
    },
};
